package com.usian.kafka.controller;

import com.alibaba.fastjson.JSON;
import com.usian.kafka.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class provider {

   @Autowired
   private KafkaTemplate<String ,Object> kafkaTemplate;

    @GetMapping("/hello")
    @ResponseBody
    public String hello(){
        //第一个参数：topics
        //第二个参数：消息内容

        User user = new User();
        user.setUsername("朱洪德");
        user.setPassword("20030303");
        kafkaTemplate.send("topic2", JSON.toJSONString(user));
       return "ok";
    }
}
